var cityList;
var curItemId = 1;
var curLoadId = 1;
$(function(){
	initData(afterInitData); return ;
	$("#scroll").pislider({
		child:"child",
		slider_bar:"slider_bar",
		scrollTime:500,
		autoScroll:"false",
		autoTime:7000,
		callback:clickBtn,
	});
});

function clickBtn(type){
	$('#cityBox'+curItemId).removeClass('active');
	if(type == 'next'){
		curItemId ++;
		if(curItemId > cityList.length){
			curItemId = 1;
		}
	}else{
		curItemId -- ;
		if(curItemId ==0){
			curItemId = cityList.length
		}
	}
	$('#cityBox'+curItemId).addClass('active');
}

function afterInitData(list){
	cityList = list;
	
	var city,j,cityCon='',con='';
	for(var i = 0;i<cityList.length;i++){
		city = cityList[i];
		j = i + 1;
		city.id=j;
		
		cityCon += '<span id="cityBox'+j+'">'+city.name+'</span>';
		con += '<div class="child" ><div class="box" id="childBox'+j+'"><div class="tip">加载中...<div></div></div>';
	}
	$('#cityList').html(cityCon);
	$('#scroll').html(con);
	
	$("#scroll").pislider({
		child:"child",
		slider_bar:"slider_bar",
		scrollTime:500,
		autoScroll:"false",
		autoTime:7000,
		callback:clickBtn,
	});
	$('#cityBox'+curItemId).addClass('active');
	
	city = cityList[0];
	loadCityData(city,afterLoadData);
}

function afterLoadData(city,data){
	
	var box = $('#childBox' +city.id);
	refreshWeather(box,city,data);
	
	curLoadId ++;
	if(curLoadId <=cityList.length){
		var city = cityList[curLoadId - 1];
		loadCityData(city,afterLoadData);
	}
}

